#!/usr/bin/python3
# -*- coding:utf-8 -*-
""""
   @Author: 叶建伟
   @Email: yejw46507@hundsun.com
   @Time: 2023/5/12 16:28
   @File: dataTest.py
"""
from faker import Faker

from random import choice

from DataTest.tabledata.commonData import randomInfo
from DataTest.tabledata.commonData.SQLMontage import read_file, get_sql_key, montage_sql_value
from DataTest.tabledata.commonData.clientInfo import client_info

fake = Faker(locale='zh_CN')


def montage_sql(**kwargs):
    table = kwargs.get('table')
    sql_list = kwargs.get('sql_list')
    sql = read_file(table)
    for key, value in sql.items():
        table_value = {}
        for key_1, value_1 in value[0].items():
            keyLower = key_1.lower()
            table_value.update({keyLower: value_1})
        table_key = get_sql_key(table=table)
        values = montage_sql_value(table=table_value, sql_list=sql_list)
        print(table_key.lower()+values+';')



if __name__ == "__main__":
    startNum = 11
    endNum = 16
    for i in range(startNum, endNum):
        str = '000249770000'
        replacement = f"{i}"
        client_id = str[:-len(replacement)] + replacement
        # inner_client_id = client_id
        client_type = '0'
        sql_list = client_info()
        # client_type = choice(['1','2'])
        # sql_list = client_info()
        # client_name = fake.company() #名称
        # occupation_code = '1'



       # contact_address = '广东省韶关市酒厂街11号'
       #  id_type = '01'
        ta_no = '63'
        apply_date = 20240621
        confirm_date = 20240621
        # id_no = '511724200609256120'
        # nationality_code = 'CAF'
        business_flag = '81'
        id_type = choice(['01','02','15','05','06','07'])
        # occupation_code = choice(['37','34','36','15','2','1','14','16','17'])
        # sql_list.update({'client_name':client_name,'client_full_name':client_name})
        sql_list.update({'client_id': client_id,'inner_client_id': client_id,'client_type': client_type,
                         'ta_no':ta_no,'id_type':id_type})
        sql_list.update({'business_flag': business_flag,'apply_date':apply_date,'confirm_date':confirm_date})
        montage_sql(table='fnd_client', sql_list=sql_list)
        montage_sql(table='fnd_fund_account', sql_list=sql_list)
        montage_sql(table='fnd_account_request', sql_list=sql_list)
        # montage_sql(table='fnd_request', sql_list=sql_list)
        # montage_sql(table='amlrc_risklevel', sql_list=sql_list)


        # 001076-易方达改革红利混合-9  003188-博时聚源纯债债券A-4 005215-南方全天候策略(FOF)A-F 006296-鹏华养老2035三年持有期混合(FOF)-G 006562-中欧短债债券C-3 159001-货币ETF-B 159937-黄金ETF基金-C
        product_code_list = ['001076','003188','005215','006296','006562','159001','159937']
        apply_amount = 60000
        apply_volume = 60000
        match_amount = 50000
        match_volume = 40000


        for i in range(7):
            apply_date = randomInfo.get_random_date()  # 申请日期
            occur_date = apply_date
            confirm_date = apply_date
            apply_no = fake.uuid4()
            serial_no = fake.uuid4()[:-4]
            business_flag = choice(['01','02','03','04'])
            product_code = product_code_list[i]
            # print(match_amount)
            if i==2:
                match_amount = match_amount + 100000
                trade_status = '2'
                sql_list.update({ 'business_flag': business_flag, 'serial_no': serial_no,
                             'apply_amount':apply_amount,'apply_volume':apply_volume ,'match_amount': match_amount, 'match_volume': match_volume
                                , 'occur_date': occur_date, 'apply_date': apply_date, 'confirm_date': confirm_date,'apply_no':apply_no, 'product_code': product_code,'trade_status': trade_status})
                montage_sql(table='fnd_request', sql_list=sql_list)

            else:

                    trade_status = '1'
                    sql_list.update({'business_flag': business_flag, 'serial_no': serial_no,
                                     'apply_amount': apply_amount, 'apply_volume': apply_volume,
                                     'match_amount': match_amount, 'match_volume': match_volume
                                        , 'occur_date': occur_date, 'apply_date': apply_date, 'confirm_date': confirm_date,
                                     'apply_no': apply_no, 'product_code': product_code, 'trade_status': trade_status})
                    montage_sql(table='fnd_request', sql_list=sql_list)

